<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">添加晨检</small>
      </a>
      <a href="javascript:;" class="save">
        <button @click="submitForm()" type="primary">保存</button>
      </a>
    </header>
    <main>
  
      <div class="formcontent">
        <ul>
          <li>
            <span> <em>*</em>晨检日期</span>
            <div class="froms">{{datatime()|time}}</div>
          </li>
          <li>
            <span><em>*</em>晨检结果{{value}}</span>
            <div class="froms">
              <el-select v-model="value" placeholder="请选择">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            
            </div>
          </li>
          <li>
            <span> <em>*</em> 姓名</span>
            <div class="froms">
              <input type="button" class="text_l"  @click="handleClick" v-model="msg">
              <!--<span @click="handleClick">{{msg}}</span>-->
              <mt-popup v-model="popupVisible" position="right" modal=false class="mint-popup-3">
                <header class="head">
                  <a class="back tl" @click="clickmodl">
                    <i class="el-icon-arrow-left"></i>
                  </a>
                  <a href="javascript:;" class="tc">
                    <small class="font_18 co_f">人员档案</small>
                  </a>
                </header>
                <main>
                  <div class="seachfrom">
                    <div class="seachbox">
                      <el-input placeholder="请输入内容" v-model="seachtext">
                        <el-button slot="append" icon="search"></el-button>
                      </el-input>
                    </div>
                  </div>
                  <div>
                    <ul class="datalist">
                      <li v-for='(item,index) of getPerson' :key='item.unid' >
                        <a :data-name="item.name"  :data-unid="item.unid" @click="peopleClick(item.unid,item.name)">
                          姓名:{{item.name}}
                        </a>
                      </li>
                    </ul>
                  </div>
                </main>
              </mt-popup>
            </div>
          </li>
        </ul>
      </div>
  
    </main>
  </div>
</template>

<script>
  import {
    MorningRecordAdd
  } from '../../api/api';
  import {
    Popup
  } from 'mint-ui';
  
  import {
    InstitutionPerson
  } from '../../api/api';
  
  export default {
    name: 'add_mrcj',
    components: {
      'mt-popup': Popup,
    },
    data() {
      return {
        msg: '请选择人员',
        getNowFormatDate: null,
        people: this.$route.query.name,
        options: [{
          value: '√',
          label: '正常'
        }, {
          value: '△',
          label: '发热'
        }, {
          value: '⊙',
          label: '腹泻'
        }, {
          value: '﹟',
          label: '皮肤溃疡'
        }, {
          value: '※',
          label: '其他传染病'
        }, {
          value: '不在岗',
          label: '不在岗位'
        }],
        value: '',
        CriteriaList: [],
        //组件
        seachtext: '',
        popupVisible: false,
        closeOnClickModal: false,
        getPerson:[],
        Enterprise: {},
        PageSize:10,
        institutionPersonname:'',
        institutionPersonunid:'',
      };
    },
  
    methods: {
      handleClick: function() {
        this.popupVisible = true
        this.getInstitutionPerson();
      },
      clickmodl: function() {
        this.popupVisible = false
      },
      //获取item
      peopleClick:function(unid,name){
          this.institutionPersonname=name;
          this.institutionPersonunid=unid;
          this.clickmodl();
          this.msg=this.institutionPersonname
      },
      //获取当前时间
      datatime: function() {
        var moment = require('moment');
        var currentdate = moment().format('YYYY-MM-DD hh:mm:ss');
        return currentdate;
      },
  
      //获取组件institutionPerson的数据
      getInstitutionPerson: function() {
      
        //定义需要传给通讯的参数：QueryData{"PageSize":10,"CurrentPage":1,"Query":{"CriteriaList":[]}}和userunid   Enterprise.Unid
        let varQueryData = {
          PageSize: this.PageSize,
          CurrentPage: 1,
          Query: {
            CriteriaList: this.CriteriaList
          }
        }
        let query = {
          Name: 'Enterprise.Unid', //Enterprise.Unid
          Value: JSON.parse(localStorage.getItem('auth')).enterpriseUnid,
          Operate: "Equal",
          DataType: null,
          EndSuffix: "",
          Suffix: null
        }
        varQueryData.Query.CriteriaList.push(query) //往数组里面添加对象
        let options = {
          params: {
            UserUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
            QueryData: JSON.stringify(varQueryData),
            //Enterprise.Unid:,
          }
        }
        //调取接口
        InstitutionPerson(options).then((res) => {
          if (res.success === true) {
            this.user = res.data.user;
            this.getPerson = res.data;
          }
        })
      },
  
  
      //提交方法
      submitForm: function() {
        //定义需要传给通讯的参数：string Data--实体MorningRecord的序列化值 string UserUnid--当前操作用户标识   stringify对象解析字符串 parse字符串解析对象
        // var options = JSON.stringify(this.options);
        let varQueryData = {
          Name: this.institutionPersonname,
          Unid: this.institutionPersonunid,
          //Unid: JSON.parse(localStorage.getItem('auth')).enterpriseUnid,//规范unid
        }
  
        let data = {
          MorningRecordDate: this.datatime(),
          MorningRecordContent: this.value,
          EnterprisePerson: varQueryData,
        }
        let dataoption = {
          params: {
            Data: JSON.stringify(data),
            UserUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
          }
        }
        //调取接口
        MorningRecordAdd(dataoption).then((res) => {
          if (res.success === true) {
            this.$message.success('保存成功');
            this.$router.go(-1);
          } else {
            this.$message.error(res.msg);
          }
        }).catch(function() {
          this.$message.error('网络异常。');
        })
  
      },
      created() {
  
      },
      //页面加载时候
      mounted() {
        this.getInstitutionPerson();
      }
  
    }
  }
</script>

<style lang="scss">
   
</style>
